const fs = require('fs');
const path = require('path');

const moveFile = (sourcePath, destDir, callback) => {
    const destPath = path.join(destDir, path.basename(sourcePath));

    // 确保目标目录存在
    if (!fs.existsSync(destDir)) {
        fs.mkdirSync(destDir, { recursive: true }); // 使用递归模式确保所有中间目录也被创建
    }

    fs.rename(sourcePath, destPath, (err) => {
        if (err) return callback(err);
        callback(null, 'File moved successfully');
    });
};

module.exports = moveFile;